<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\admin\model;
use think\Model;
use think\facade\Db;

class Brand extends Model{
    /**列表
    * signid 1显示9已删除，大于9就是删除时间戳
    * lang 语言
    * keyword 关键词
    * order 排序
    */
	static function index($signid,$lang,$keyword,$order){
		$keyword = trim($keyword);
		$where[] = ['lang','=',$lang];
		if($signid > 8){//已软删除
			$where[] = ['signid','>','8'];
		}else{
			$where[] = ['signid','=',$signid];
		}

		$pageParam = array('lang'=>$lang);
		$pageParam += array('signid'=>$signid);
		$pageParam += array('keyword'=>$keyword);

		$rs = Db::name('brand')->where($where)->where('title|keyword|description|content1','like',"%$keyword%")->order($order)
			->paginate([
            	'list_rows'=> 20,
            	'query'=> $pageParam,
            ]);
		return $rs;
	}

	// urlroute小写
    protected function setUrlrouteAttr(){
		return strtolower(msubstr(input('urlroute'),0,100,''));
    }

	// 索引字母大写
    protected function setInitialAttr(){
		return ucfirst(msubstr(input('initial'),0,1,''));
    }
    
    //新增编辑
	static function edit($id){
	    if($id > 0){//编辑
			$brand = Brand::find($id);
		}else{//新增
			$brand = new Brand;
		}
		$brand->save(input('post.'));
		return $brand->id;
	}
}